package deviceinfo.wsm.com.deviceinfo.common;

/**
 * Created by 王家宝 on 2018/7/5.
 * TEL:18241150668
 * MAIL:639586819@qq.com
 */

public class FormatUtils {

    public static String formatSize(long size) {
        String suffix = null;
        float fSize=0;

        if (size >= 1024) {
            suffix = "KB";
            fSize=size / 1024;
            if (fSize >= 1024) {
                suffix = "MB";
                fSize /= 1024;
            }
            if (fSize >= 1024) {
                suffix = "GB";
                fSize /= 1024;
            }
        } else {
            fSize = size;
        }
        java.text.DecimalFormat df = new java.text.DecimalFormat("#0.00");
        StringBuilder resultBuffer = new StringBuilder(df.format(fSize));
        if (suffix != null)
            resultBuffer.append(suffix);
        return resultBuffer.toString();
    }


    public static String formatCpuRate(long khz) {
        String suffix = null;
        float fSize=0;

        if (khz >= 1000) {
            suffix = "MHz";
            fSize=khz / 1000;
            if (fSize >= 1000) {
                suffix = "GHz";
                fSize /= 1000;
            }
        } else {
            fSize = khz;
        }
        java.text.DecimalFormat df = new java.text.DecimalFormat("#0.00");
        StringBuilder resultBuffer = new StringBuilder(df.format(fSize));
        if (suffix != null)
            resultBuffer.append(suffix);
        return resultBuffer.toString();
    }
}
